import AuthRoute from "@/components/AuthRoute";
import Layout from "@/pages/Layout";
import Login from "@/pages/Login"
import { Suspense, lazy } from "react";
import { createBrowserRouter } from "react-router-dom";

//路由懒加载
const Home = lazy(()=>import('@/pages/Home'))
const Acticles = lazy(()=>import('@/pages/Acticles'))
const Publish = lazy(()=>import('@/pages/Publish'))
const Acticle = lazy(()=>import('@/pages/Acticle'))
const Mine = lazy(()=>import('@/pages/mine'))


const All = lazy(()=>import('@/pages/About/All'))
const Before = lazy(()=>import('@/pages/About/before'))
const After = lazy(()=>import('@/pages/About/After/index'))
const Other = lazy(()=>import('@/pages/About/Other'))



const router= createBrowserRouter([
    {
        path:"/",
        element:<AuthRoute> <Layout/> </AuthRoute>,
        children:[
            {
                path:'all',
                element:<Suspense fallback={'加载中'}><Home/></Suspense>,
                children:[
                    {
                        index:true,
                        element:<Suspense fallback={'加载中'}><All/></Suspense> 
                    },
                    {
                        path:'/all/before',
                        element:<Suspense fallback={'加载中'}><Before/></Suspense> 
                    },
                    {
                        path:'/all/after',
                        element:<Suspense fallback={'加载中'}><After/></Suspense> 
                    },
                    {
                        path:'/all/other',
                        element:<Suspense fallback={'加载中'}><Other/></Suspense> 
                    },
                ]
            },
            {
                path:'articles',
                element:
                <Suspense fallback={'加载中'}><Acticles/></Suspense> 
            },
            {
                path:'publish',
                element:
                <Suspense fallback={'加载中'}><Publish/></Suspense> 
            }
        ]
    },
    {
        path:"/login",
        element:<Login/>
    },
    {
        path:"/article",
        element:
        <Suspense fallback={'加载中'}><Acticle/></Suspense>
    },
    {
        path:"/mine",
        element:
        <Suspense fallback={'加载中'}><Mine/></Suspense>
    },
    

])

export default router